//
//  AddViewController.m
//  UIHomeWork08-通讯录
//
//  Created by tusm on 16/7/25.
//  Copyright © 2016年 tusm. All rights reserved.
//


#import "AddViewController.h"
#import "ViewController.h"


@interface AddViewController ()
@property(nonatomic,strong)UITextField * textFiledName;
@property(nonatomic,strong)UITextField * textFiledAge;
@property(nonatomic,strong)UITextField * textFiledGender;
@property(nonatomic,strong)UITextField * textFiledTele;
@property(nonatomic,strong)NSMutableDictionary * dictionary;
@end

@implementation AddViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    UILabel * labelName = [[UILabel alloc]initWithFrame:CGRectMake(100, 100, 100, 50)];
    labelName.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:labelName];
    _textFiledName = [[UITextField alloc]initWithFrame:CGRectMake(200, 100, 100, 50)];
    _textFiledName.backgroundColor = [UIColor lightGrayColor];;
    [self.view addSubview:_textFiledName];
    UILabel * labelAge = [[UILabel alloc]initWithFrame:CGRectMake(100, 200, 100, 50)];
    labelAge.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:labelAge];
    _textFiledAge = [[UITextField alloc]initWithFrame:CGRectMake(200, 200, 100, 50)];
    _textFiledAge.backgroundColor =[UIColor lightGrayColor];;
    [self.view addSubview:_textFiledAge];
    UILabel * labelGender = [[UILabel alloc]initWithFrame:CGRectMake(100, 300, 100, 50)];
    labelGender.backgroundColor = [UIColor lightGrayColor];;
    [self.view addSubview:labelGender];
    _textFiledGender = [[UITextField alloc]initWithFrame:CGRectMake(200, 300, 100, 50)];
    _textFiledGender.backgroundColor = [UIColor lightGrayColor];;
    [self.view addSubview:_textFiledGender];
    
    UILabel * labelTele = [[UILabel alloc]initWithFrame:CGRectMake(100, 400, 100, 50)];
    labelTele.backgroundColor = [UIColor lightGrayColor];
    [self.view addSubview:labelTele];
    _textFiledTele = [[UITextField alloc]initWithFrame:CGRectMake(200, 400, 100, 50)];
    _textFiledTele.backgroundColor = [UIColor lightGrayColor];;
    [self.view addSubview:_textFiledTele];
    labelName.text = @"姓名";
    labelAge.text = @"年龄";
    labelGender.text = @"性别";
    labelTele.text = @"电话号码";
    labelName.textAlignment = NSTextAlignmentCenter;
    labelAge.textAlignment = NSTextAlignmentCenter;
    labelGender.textAlignment = NSTextAlignmentCenter;
    labelTele.textAlignment = NSTextAlignmentCenter;
    
    UIButton * saveButton = [UIButton buttonWithType:(UIButtonTypeSystem)];
    [saveButton setFrame:CGRectMake(0, 0, 100, 50)];
    saveButton.center = CGPointMake(375 / 2, 500);
    saveButton.backgroundColor = [UIColor purpleColor];
    [saveButton setTitle:@"保存" forState:(UIControlStateNormal)];
    [self.view addSubview:saveButton];
    [saveButton addTarget:self action:@selector(clickSaveButton:) forControlEvents:(UIControlEventTouchUpInside)];
    // Do any additional setup after loading the view.
}
-(void)clickSaveButton:(UIButton *)button{
    _dictionary  = [NSMutableDictionary dictionary];
    [_dictionary setObject:_textFiledName.text forKey:@"name"];
    [_dictionary setObject:_textFiledAge.text forKey:@"age"];
    [_dictionary setObject:_textFiledGender.text forKey:@"gender"];
    [_dictionary setObject:_textFiledTele forKey:@"phoneNumber"];
    [self.delegate PassValue:_dictionary];
    [self.navigationController popToRootViewControllerAnimated:YES];
    
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end
